<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:jsp="http://java.sun.com/JSP/Page"
	xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core" xmlns:a4j="http://richfaces.org/a4j" xmlns:rich="http://richfaces.org/rich">
	<jsp:directive.page language="java" import="java.util.*" pageEncoding="UTF-8" />
	<ui:composition template="/protected/layout/template.xhtml">
		<head>
			<ui:define name="head">
				<title><h:outputText value="#{backApp.fullTitle}" />Manutenção de Cadastro!</title>
			</ui:define>
		</head>
		<body>
			<ui:define name="body">
				<rich:panel>
					<f:facet name="header">
						<h3 align="center">
							Manutenção de Cadastro
						</h3>
					</f:facet>
					<rich:panel id="userPanel">
						<f:facet name="header">
							<h4 align="center">
								Dados do Usuário
							</h4>
						</f:facet>
						<h:form prependId="false">
							<h:panelGrid columns="3">
								<rich:column colspan="1">
									<h:outputLabel for="tfReduzedId" value="Id Reduzido:"
										title="Id Reduzido pode ser utilizado para identificar rapidamente o Usuário" />
									<br />
									<h:panelGroup>
										<h:inputText size="6" id="tfReduzedId" required="false" rendered="true"
											value="#{userRecordsManager.user.reduzedId}" maxlength="6" />
										<h:message for="tfReduzedId" />
									</h:panelGroup>
								</rich:column>
								<rich:column colspan="1">
									<h:outputLabel for="tfUUID" value="UUID:" />
									<br />
									<h:inputText readonly="true" size="50" id="tfUUID" required="true" rendered="true"
										value="#{userRecordsManager.user.registrationId}" />
								</rich:column>
								<rich:column colspan="1">
									<h:outputLabel for="tfUserAka" value="Apelido (Como gosta de ser chamado):" />
									<br />
									<h:panelGroup>
										<h:inputText size="20" id="tfUserAka" required="false" value="#{userRecordsManager.user.aka}" />
										<h:message for="tfUserAka" />
									</h:panelGroup>
								</rich:column>
								<rich:column colspan="4">
									<h:outputLabel for="tfUserName" value="Nome:" />
									<br />
									<h:panelGroup>
										<h:inputText size="60" id="tfUserName" required="true" rendered="true" value="#{userRecordsManager.user.name}" />
										<h:message for="tfUserName" />
									</h:panelGroup>
								</rich:column>
								<rich:spacer />
								<rich:spacer />
								<rich:column colspan="1">
									<h:outputLabel for="tfUserEmail" value="E-mail:" />
									<br />
									<h:panelGroup>
										<h:inputText size="40" id="tfUserEmail" required="true" rendered="true"
											value="#{userRecordsManager.user.email}" />
										<h:message for="tfUserEmail" />
									</h:panelGroup>
								</rich:column>
								<rich:column colspan="1">
									<h:outputLabel for="tfRegistrationDate" value="Data de Registro:" />
									<br />
									<h:panelGroup>
										<h:inputText readonly="true" size="30" id="tfRegistrationDate" required="true" rendered="true"
											value="#{userRecordsManager.user.registrationDate}" />
									</h:panelGroup>
								</rich:column>
								<rich:column colspan="1">
									<h:outputLabel for="tfLastUpdateDate" value="Data Última Atualização:" />
									<br />
									<h:panelGroup>
										<h:inputText readonly="true" size="30" id="tfLastUpdateDate" required="true" rendered="true"
											value="#{userRecordsManager.user.lastUpdateDate}" />
									</h:panelGroup>
								</rich:column>
							</h:panelGrid>
							<rich:spacer height="20" />
							<a4j:region>
								<center>
									<a4j:commandButton id="saveUserButton" value="Salvar" action="#{userRecordsManager.saveBaseUserRecord}"
										status="statusSaveUserButton" reRender="userPanel" />
									<rich:spacer width="20" />
									<h:commandButton value="Restaurar" action="#{loginManager.restoreBaseUserRecord}" type="reset" />
									<br />
									<a4j:status id="statusSaveUserButton" startText="Salvando" stopText="" />
								</center>
							</a4j:region>
						</h:form>
					</rich:panel>
					
					<!-- ## Dados de endereços ## -->
					<rich:panel>
						<f:facet name="header">
							<h5 align="center">
								Endereço
							</h5>
						</f:facet>
						<h:form prependId="false">
							<h:panelGrid columns="3">
								<rich:column colspan="1">
									<h:outputLabel for="tfLogradouro" value="Logradouro:" title="Escolha o tipo de logradouro, Rua, Av. Praça..." />
									<br />
									<h:panelGroup>
										<h:selectOneMenu  id="ltLogradouro" required="true" rendered="true"
											value="#{addressManager.addressType}" valueChangeListener="#{addressManager.addressTypeSelectListener}">
											<f:selectItems value="#{addressManager.addressTypes}" />
											</h:selectOneMenu>
										<h:message for="tfLogradouro" />
									</h:panelGroup>
								</rich:column>
							</h:panelGrid>
						</h:form>
					</rich:panel>
					
					<!-- ## Dados da Empresa ## -->
					<rich:panel id="recordsClientsPanel">
						<h:form>
							<h:panelGrid columns="2">
								<f:facet name="header">
									<h:outputText value="É Responsavel por uma ou mais Empresa?" />
								</f:facet>
								<h:selectOneMenu value="#{userRecordsManager.workerAtClients}" id="sltResponsability"
									valueChangeListener="#{userRecordsManager.selectedWorkerAtClients}"
									title="Apos selecionar, indique o numero de empresas que atua com contratado direto">
									<f:selectItems value="#{userRecordsManager.selectItensYesNo}" />
									<a4j:support event="onchange" reRender="recordsClientsPanel" />
								</h:selectOneMenu>
								<h:panelGroup id="numClientsPanel" rendered="#{userRecordsManager.workerAtClients}">
									<h:outputLabel for="numClients" value="Numero de empresas:" />
									<h:outputText id="numClients" value="#{userRecordsManager.numClientsForUser}" />
								</h:panelGroup>
							</h:panelGrid>
							<rich:spacer />
							<a4j:region>
								<h:panelGrid columns="2">
									<a4j:commandButton status="statusProcessClientTable" value="Adicionar Empresa"
										action="#{userRecordsManager.addMoreWorkForUser}">
									</a4j:commandButton>
									<a4j:commandButton status="statusProcessClientTable" action="#{userRecordsManager.removeSelectedWorkForUser}"
										value="Remover Empresa" />
									<rich:column colspan="2">
										<a4j:status id="statusProcessClientTable" startText="Processando Registro da Tabela" stopText="" />
									</rich:column>
								</h:panelGrid>
							</a4j:region>
						</h:form>
						<rich:panel id="clientsPanel" rendered="#{userRecordsManager.workerAtClients}">
							<f:facet name="header">
								<h3 align="center">
									<h:outputText value="Dados das Empresas pela qual é responsável"
										rendered="#{userRecordsManager.numClientsForUser gt 1}" />
									<h:outputText value="Dado da Empresa pela qual é responsável"
										rendered="#{not (userRecordsManager.numClientsForUser gt 1)}" />
								</h3>
							</f:facet>
							<h:panelGrid>
								<h:form prependId="false">
									<ui:include src="/protected/listAllWorks.xhtml">
										<ui:param name="works" value="#{userRecordsManager.works}" />
									</ui:include>
									<a4j:region>
										<center>
											<a4j:commandButton value="Editar Empresa Selecionada" reRender="clientModalTable"
												action="#{userRecordsManager.takeWorkSelected}"
												oncomplete="javascript:Richfaces.showModalPanel('clientDetails');" status="statusEditClient" />
											<br />
											<a4j:status id="statusEditClient" startText="Processando Registro da Tabela" stopText="" />
										</center>
									</a4j:region>
								</h:form>
								<!-- 
									################################################### 
									-->
								<rich:modalPanel id="clientDetails" autosized="true">
									<f:facet name="header">
										<h3>
											<h:outputText value="Editar Empresa" />
										</h3>
									</f:facet>
									<f:facet name="controls">
										<span style="cursor: pointer" onclick="javascript:Richfaces.hideModalPanel('clientDetails')"><b>X</b> </span>
									</f:facet>
									<h:form>
										<ui:include src="/protected/editWorkAtClient.xhtml">
											<ui:param name="roles" value="#{userRecordsManager.roleTypesForUserWorkOnClient}" />
											<ui:param name="work" value="#{userRecordsManager.atualWork}" />
										</ui:include>
										<a4j:region>
											<center>
												<h:commandButton value="Salvar" action="#{userRecordsManager.saveEditAtualWork}" />
												<a4j:commandButton value="Cancelar" reRender="clientsTable"
													action="#{userRecordsManager.cancelEditAtualWork}"
													oncomplete="javascript:Richfaces.hideModalPanel('clientDetails')" />
												<br />
												<a4j:commandButton value="Selecionar um client existente" reRender="clientModalTable"
													action="#{clientRecordsManager.listAllClients}"
													oncomplete="javascript:Richfaces.showModalPanel('listAllClientsPanel');" status="statusListAllClientTable" />
												<br />
												<a4j:status id="statusListAllClientTable" startText="Listando Clientes Existente" stopText="" />
											</center>
										</a4j:region>
									</h:form>
								</rich:modalPanel>
								<rich:modalPanel id="listAllClientsPanel" autosized="true">
									<f:facet name="header">
										<h3>
											<h:outputText value="Todos os Clientes" />
										</h3>
									</f:facet>
									<f:facet name="controls">
										<span style="cursor: pointer" onclick="javascript:Richfaces.hideModalPanel('listAllClientsPanel')"><b>X</b>
										</span>
									</f:facet>
									<ui:include src="/protected/listAllClients.xhtml">
										<ui:param name="selection" value="#{clientsRecordsManager.selectedClient}" />
										<ui:param name="value" value="#{clientsRecordsManager.allClients}" />
									</ui:include>
									<a4j:commandButton value="Selecionar" action="#{userRecordsManager.takeSelectedClient}"
										oncomplete="javascript:Richfaces.hideModalPanel('listAllClientsPanel')" reRender="clientDetails" />
								</rich:modalPanel>
							</h:panelGrid>
						</rich:panel>
					</rich:panel>
				</rich:panel>
			</ui:define>
		</body>
	</ui:composition>
</html>
